package IC.SymbolTable;

import java.util.HashMap;
import java.util.LinkedHashMap;
import IC.Constants;

public class BlockSymbolTable extends RecursiveLookupSymbolTable {

	private static int uniqueIDCounter = 1;			
	private LinkedHashMap<String,Symbol> Locals;	    //Block Inner Symbol Table
	
	//C'tor
	public BlockSymbolTable(String id) {
		super(id + " (" + uniqueIDCounter++ + ")",id);
		Locals = new LinkedHashMap<String,Symbol>();
	}
	
	@Override
	public Symbol getValue(String id) {
		return Locals.get(id);
	}

	@Override
	protected HashMap<String, Symbol> getInnerHashMap(SymbolKind kind, int lineNumber) {
		return Locals;
	}
	
	@Override
	public String toString() {
		String str = Title() +  Constants.LINE_BREAK;
		for (Symbol symbol : Locals.values()) 
			str += Constants.SPACE + symbol +  Constants.LINE_BREAK;
		str += childrensToString();
		return str;
	}

	@Override
	public String Title() {
		return "Statement Block Symbol Table ( located in " + getParent().getDisplayId() + " )";
	}
		
}
